package com.chess.touch.demo;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.RelativeLayout;
import android.widget.RelativeLayout.LayoutParams;
import android.widget.TextView;

public class MainActivity extends UActivity {

	private RelativeLayout topView = null;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		topView = (RelativeLayout)this.findViewById(R.id.top_view);
		addTextView();

	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.activity_main, menu);
		return true;
	}

	/**
	 * Handle menu "click".
	 * 
	 * @param itm
	 *            The menu item selected.
	 * @return True if the event was handled.
	 */
	@Override
	public boolean onOptionsItemSelected(MenuItem itm) {
		switch (itm.getItemId()) {
		case R.id.add_image_view:
			addImageView();
			return true;

		case R.id.add_text_view:
			addTextView();
			return true;
		default:
			return super.onOptionsItemSelected(itm);
		}
	}

	@SuppressWarnings("unused")
	private void addTextViewV0() {
		LayoutInflater inflater = (LayoutInflater)getSystemService(LAYOUT_INFLATER_SERVICE);
		View view = inflater.inflate(R.layout.document_annotation_text_view, null);
		TextView textView = (TextView)view.findViewById(R.id.text_id);
		textView.setText("测试");
		// view.setOnTouchListener(this);
		LayoutParams params = new LayoutParams((int)getResources().getDimension(R.dimen.annotation_default_width),
				(int)getResources().getDimension(R.dimen.annotation_default_height));
		params.addRule(RelativeLayout.CENTER_IN_PARENT);
		topView.addView(view, params);

	}

	private void addTextView() {
		TextViewAnnotation view = new TextViewAnnotation(this, "测试一下");
		LayoutParams params = new LayoutParams((int)getResources().getDimension(R.dimen.annotation_default_width),
				(int)getResources().getDimension(R.dimen.annotation_default_height));
		params.addRule(RelativeLayout.CENTER_IN_PARENT);
		topView.addView(view, params);

	}

	private void addImageView() {

	}

}
